﻿@model QuanLyGiaoVuUI.Models.QuanLySinhVien.NhapDieuKienLuanVanViewModel

@{
    Layout = null;
    }

<style>
    .hiddenField {
        display: none;
    }
</style>
<script src="@Url.Content("~/Scripts/jquery.form.js")"></script>
<script src="~/Scripts/jquery.unobtrusive-ajax.min.js"></script>
@{using (Ajax.BeginForm("NhapDieuKienLuanVanTuFile", "QuanLySinhVien", new AjaxOptions {
      HttpMethod = "POST",
      OnSuccess = "OnSuccessCallBack"
  })) {
<table border="0" cellpadding="0" cellspacing="0" id="id-form" class="form">
        <tr>
            <th valign="top">@Html.LabelFor(model => model.StartRowIndex)</th>
            <td>@Html.TextBoxFor(model => model.StartRowIndex, new { @class="large"})</td>
            <td>@Html.ValidationMessageFor(model => model.StartRowIndex)</td>
        </tr>
        <tr>
            <th valign="top">@Html.LabelFor(model => model.EndRowIndex)</th>
            <td>@Html.TextBoxFor(model => model.EndRowIndex, new { @class="large"})</td>
            <td>@Html.ValidationMessageFor(model => model.EndRowIndex)</td>        
        </tr>
        <tr>
            <th valign="top">@Html.LabelFor(model => model.IdentityColumnIndex)</th>
            <td>@Html.TextBoxFor(model => model.IdentityColumnIndex, new { @class="large"})</td>
            <td>@Html.ValidationMessageFor(model => model.IdentityColumnIndex)</td>
        </tr>
       <tr>
            <th valign="top">@Html.LabelFor(model => model.ValueColumnIndex)</th>
            <td>@Html.TextBoxFor(model => model.ValueColumnIndex, new { @class="large"})</td>
            <td>@Html.ValidationMessageFor(model => model.ValueColumnIndex)</td>
        </tr>
    </table>
    @Html.HiddenFor(model => model.MaTapTin)
    <input type="hidden" id="filename" value="" />
    <input type="submit" id="btnSubmitDuLieu" style="display: none" />
  }}

    <form id="uploadFile" name="UploadFile" action="/QuanLySinhVien/UploadFile" method="post">
    <table>
        <tr>
            <th valign="top">File dữ liệu:</th>
            <td>
                <input type="file" name="fileTaiLieu" id="file" />
            </td>
        </tr>
    </table>
    <div id="loadingImage" class="hiddenField ui-overlay">
        <img src="~/Images/gif/loading-bar.gif" /></div>

    <input type="submit" id="uploadFileSubmit" style="display: none;" />
</form>    

    <input type="submit" id="submitTaoTaiLieu" value="" class="hiddenField" />

<script>
    $(document).ready(function () {
        $("input:file").change(function () {
            $("#filename").val($(this).val());
        });

        $("#StartRowIndex").spinner({
            min: 1
        });
        $("#EndRowIndex").spinner({
            min: 1
        });

        $("#uploadFile").ajaxForm({
            dataType: 'json',
            success: uploadFileSuccess,
            beforeSubmit: beforeUploadFile,
            error: uploadFileFail,
            uploadProgress: showProgress
        });
    });

    function uploadFileSuccess(data) {
        $("#loadingImage").addClass("hiddenField");
        $("#MaTapTin").val(data.fileId);
        $("#TenTapTin").val(data.fileName);
        $("#KichThuoc").val(data.fileSize);
        $("#btnSubmitDuLieu").click();
    }

    function uploadFileFail() {
        $("#loadingImage").addClass("hiddenField");
        ToastManager.showStickyWarningToast("Không thể upload file.");
    }

    function showProgress(event, position, total, percentComplete) {
        $("#position").val(position);
    }

    function SubmitNhapDuLieu() {
        if ($("#filename").val().length > 0)
            $("#uploadFileSubmit").click();
        else
            ToastManager.showStickyWarningToast("Chưa chọn file.");
    }

    function beforeUploadFile() {
        $("#loadingImage").removeClass("hiddenField");
    }

    function OnSuccessCallBack(data) {
        if (data.success) {
            ToastManager.showSuccessToast("Nhập dữ liệu thành công.");
            var myTimeout = setTimeout(function () {
                location.reload(true);
            }, 1000);
        }
        else
            ToastManager.showStickyWarningToast(data.message);
    }
</script>